package GameEngine.Gui.Event;

import java.util.ArrayList;

public class TouchEventProcessor {

	// Events to be broadcast to the sketch
	private ArrayList<TouchEvent> events;
	private ArrayList<IMultiTouchEventListener> listeners;

	public TouchEventProcessor() {
		// TODO Eventprozessor sinnvoll initialisieren
		events = new ArrayList<TouchEvent>();
		listeners = new ArrayList<IMultiTouchEventListener>();
	}

	// Listeners, die sich registriert haben

	public void add(TouchEvent e) {
		if (e != null) {
			events.add(e);
		}
	}

	public void registerListener(IMultiTouchEventListener l) {
		listeners.add(l);
	}

	// send events to the sketch
	public void sendEvents() {
		for (int i = 0; i < events.size(); i++) {
			TouchEvent e = events.get(i);

			// Differenzierung nach Events
			if (e instanceof TapEvent) {
				// onTap( (TapEvent)e )
				;
			}
			if (e instanceof TouchEvent) {
				processTouchEvents((TouchEvent) e);
			}

		}
		events.clear();
	}

	private void processTouchEvents(TouchEvent e) {
		for(IMultiTouchEventListener l: listeners) {
			l.onTouch(e);
		}
	}
}
